package org.stwy.lease.contract;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.rap.common.exception.ServiceException;
import com.rap.common.service.IService;
import com.rap.frame.web.ActionResultModel;
import com.rap.frame.web.BaseController;
import com.rap.frame.web.QueryRequest;

/*
 * 合同 控制类
 */
/**
*版权信息 (c) RAP 保留所有权利.
*@author Rap.Codegen
*@Team RAP Team
*@Date 2015-4-17 20:48:15
*<p></p>
*
*@参与人：Rap.Codegen
*/

@Controller
@RequestMapping(value = "/lease/contractasset")
public class ContractAssetController extends BaseController<ContractAssetEntity> {

	private ContractAssetService getService(){
		return (ContractAssetService)super.baseService;
	}

	@RequestMapping(method = RequestMethod.GET)
	public String view(Model model) {
		return "";
	}
	@Override
	protected ActionResultModel<ContractAssetEntity> execQuery(QueryRequest<ContractAssetEntity> qr, IService service) {
		ActionResultModel<ContractAssetEntity> arm = new ActionResultModel<ContractAssetEntity>();
		try {
			if (qr.getPageRequest() != null) {
				Page<ContractAssetEntity> data = service.findAll(qr.getSpecification(),
						qr.getPageRequest());
				arm.setRecords(data.getContent());
				arm.setTotal(data.getTotalElements());
				arm.setTotalPages(data.getTotalPages());
				arm.setPageNumber(data.getNumber());
			} else {
				List<ContractAssetEntity> list = service.findAll(qr.getSpecification(),
						qr.getSort());
				arm.setRecords(list);
				arm.setTotal(list.size());
				arm.setTotalPages(1);
			}
			arm.setSuccess(true);
		} catch (ServiceException e) {
			arm.setSuccess(false);
			arm.setMsg(e.getMessage());
			e.printStackTrace();
		}

		return arm;
	}
}
